import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *

class tool(QMainWindow):
    def __init__(self):
        super().__init__()
        self.initUI()#获取菜单栏

    def initUI(self):
        self.setWindowTitle("工具栏例子")
        self.resize(300,200)
        tb1=self.addToolBar("文件")

        new=QAction("文件",self)
        tb1.addAction(new)

        new2=QAction("输出",self)
        tb1.addAction(new2)

if __name__ == '__main__':
    app=QApplication(sys.argv)
    my=tool()
    my.show()
    sys.exit(app.exec_())